{% load staticfiles %}
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>X维度-{% block title %}{% endblock %}</title>
    <link rel="stylesheet" href="{% static 'bootstrap-3.3.7/css/bootstrap.min.css' %}">
    <script src="{% static 'js/jquery.min-1.12.4.js' %}"></script>
    <script src="{% static 'bootstrap-3.3.7/js/bootstrap.min.js' %}"></script>
    <link rel="stylesheet" href="{% static 'css/base.css' %}">
    {% block style %}{% endblock %}
</head>

<body>
    <div class="navbar navbar-default">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-8 col-md-offset-1">
                    <!-- 导航条开始 -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                                data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand logo" href="{% url 'home' %}">X维度</a>
                    </div>

                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                            <li class="{% block nav_home_active %}{% endblock %}">
                                <a href="{% url 'home' %}">首页</a></li>
                            <li class="{% block nav_blog_active %}{% endblock %}">
                                <a href="{% url 'blog_list' %}">博客</a>
                            </li>
                        </ul>
                        <ul class="nav navbar-nav navbar-right">
                            {% if request.user.is_authenticated %}
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                   aria-haspopup="true" aria-expanded="false"><span
                                          class="glyphicon glyphicon glyphicon-user">{{ request.user.get_nickname_or_username }}</span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="{% url 'user_info' %}">个人中心</a></li>
                                    <li role="separator" class="divider"></li>
                                    {% if request.user.is_superuser or request.user.is_staff %}
                                    <li><a href="{% url 'admin:index' %}">后台管理</a></li>
                                    <li role="separator" class="divider"></li>
                                    {% endif %}
                                    <li><a href="{% url 'change_password' %}?from={{ request.get_full_path }}">修改密码</a>
                                    </li>
                                    <li><a href="{% url 'logout' %}?from={{ request.get_full_path }}">退出</a></li>
                                    {% else %}
                                    <li><a href="{% url 'login' %}">登录</a></li>
                                    <li><a href="{% url 'register' %}">注册</a></li>
                                    {% endif %}
                                </ul>
                    </div><!-- /.navbar-collapse -->
                    <!-- 导航条结束 -->
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </div>

    <!-- 主体内容开始 -->
    {% block content %}
    {% endblock %}
    <!-- 主体内容结束 -->

    <!-- Modal 登录表单-->
    <div class="modal fade" id="login_modal" tabindex="-1" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <form id="login_modal_form" action="" method="POST">
                    {% csrf_token %}
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                  aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">登录</h4>
                    </div>
                    <div class="modal-body">
                        {% for field in login_modal_form %}
                        <div class="form-group">
                            <label for="{{ field.id_for_label }}">
                                {{ field.label }}
                            </label>
                            {{ field }}
                        </div>
                        {% endfor %}
                        <span id="login_modal_tip" class="text-danger"></span>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary pull-left">登录</button>
                        <button type="button" class="btn btn-default pull-right" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- Modal 登录表单提交 -->
    <script>
        $("#login_modal_form").submit(function (event) {
            event.preventDefault()
            $.ajax({
                url: "{% url 'login_for_modal' %}",
                type: 'POST',
                data: $(this).serialize(),
                cache: false,
                success: function (data) {
                    if (data['status'] == 'success') {
                        window.location.reload()
                    } else {
                        $("#login_modal_tip").text('用户名称或密码不正确')
                    }
                }
            })
        })
    </script>
    {% block script_extend %}{% endblock %}
</body>

</html>
